;(function () {
  new Vue({
    el:'#wx_message-list',
    data:{
      messageList:[],
      permissions: JSON.parse(window.localStorage.getItem('permissions')),
      configFlag:false   // 修改配置
    },
    filters:{
      formatDate:function (item) {
        return hlDateUtil.formatUTCDate(item)
      },
      formatUndefined:function (item) {
        if(item == undefined)return '--'
        return item
      }
    },
    methods:{
      // 获取流程列表数据
      getListData:function() {
        var self = this;
        var type = JSON.parse(window.localStorage.getItem('userMes')).oauthType;
        hlhttp.get({
          url:'wxpn_message_templates',
          data:{wxpn_id:'#',channel:type},
          success:function(data){
            self.messageList = data
          }
        })
      },
      // 消息模板停用启用
      changeValid:function(id,valid){
        var self = this;
        hlhttp.put({
          url:'wxpn_message_template/valid',
          data:{wxpn_message_template_id:id,opt:valid},
          success:function(data){
            hl.toast('模版状态更改成功！')
            var index = 0;
            self.messageList.map(function(_item){
              if(_item.id === id){
                self.messageList[index]['valid'] = valid
              }
              index++;
            })
          }
        })
      },
      // 前往消息模版配置
      config:function (id) {
        hlUrlUtil.goTo('wxMessageConfig',{id:id,ddtab:true},true)
      }
    },
    mounted:function () {
      this.getListData()
    }
  })
}())
